const LabelService = require("../service/label.service");

class LabelController {
	// 创建标签
	async create(ctx, next) {
		// 获取用户请求传递的参数
		const { name } = ctx.request.body;
		// 创建标签
		const result = await LabelService.create(name);
		// 返回数据
		ctx.body = {
			code: 200,
			message: "创建标签成功",
			data: result
		};
	}

	// 获取标签
	async list(ctx, next) {
		// 获取数据(offset/size)
		const { offset, size } = ctx.query;
		const result = await LabelService.getLabelList(offset, size);
		// 返回数据
		ctx.body = result;
	}

	// 修改标签
	async update(ctx, next) {
		const { name } = ctx.request.body;
		const id = ctx.request.params.labelId;
		const result = await LabelService.update(name, id);
		// 返回数据
		ctx.body = {
			code: 200,
			message: "修改标签成功",
			data: result
		};
	}

	// 删除标签
	async remove(ctx, next) {
		const id = ctx.request.params.labelId;
		const result = await LabelService.remove(id);
		// 返回数据
		ctx.body = {
			code: 200,
			message: "删除标签成功",
			data: result
		};
	}
}

module.exports = new LabelController();
